package close.mazegame.input.playerinput;

import close.mazegame.level.Level;
import close.mazegame.input.KeyboardInput;
import close.mazegame.input.playerinput.PlayerInput.PlayerKeys;

import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class KMPlayerController extends KeyboardInput<PlayerKeys> implements PlayerInput {
	
	private Level level;
	
	public KMPlayerController(Level level) {
		this.level = level;
		controlScheme.put(Keys.W, PlayerKeys.UP);
		controlScheme.put(Keys.S, PlayerKeys.DOWN);
		controlScheme.put(Keys.A, PlayerKeys.LEFT);
		controlScheme.put(Keys.D, PlayerKeys.RIGHT);
		controlScheme.put(Keys.SPACE, PlayerKeys.FIRE);
		controlScheme.put(Keys.Q, PlayerKeys.TOGGLE_FIXTURRET);
	}

	@Override
	public Vector2 getTurretDirection() {
		Vector3 worldPointer = new Vector3(pointer.x, pointer.y, 0);
		level.getCam().unproject(worldPointer);
		Vector2 turretDir = new Vector2();
		turretDir.x = worldPointer.x - level.getPlayerPosition().x;
		turretDir.y = worldPointer.y - level.getPlayerPosition().y;
		return turretDir;
	}

	@Override
	public Vector2 getMovementDirection() {
		Vector2 dir = new Vector2(0, 0);
		if (isPressed(PlayerKeys.UP)) {
			dir.y += 1;
		}
		if (isPressed(PlayerKeys.DOWN)) {
			dir.y -= 1;
		}
		if (isPressed(PlayerKeys.RIGHT)) {
			dir.x += 1;
		}
		if (isPressed(PlayerKeys.LEFT)) {
			dir.x -= 1;
		}
		dir.nor();
		return dir;
	}

}
